<template>
  <div style="height: 50px; line-height: 50px; border-bottom: 1px solid #ccc; display: flex">
    <div style="width: 200px; padding-left: 30px; font-weight: bold; color: cornflowerblue">后台管理</div>
    <div style="flex: 1"></div>
    <div style="width: 100px">

<!--       <span v-if="name == null" class="el-dropdown-link">-->
<!--          <span @click="$router.push('/login')">登录</span> <span @click="$router.push('/register')">注册</span>-->
<!--        </span>-->


      <el-dropdown>
        <span v-if="this.name.username != null" class="el-dropdown-link">
        {{ this.name.username }}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="$router.push('/Person')">个人信息</el-dropdown-item>
            <el-dropdown-item @click="$router.push('/login')">退出系统</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>

  </div>
</template>

<script>
export default {
  name: "header",

  created() {
    this.load();

  },

  data() {
    return {
      name:'',

    }
  },


  methods: {

    load() {
      //声明一个name存session的数据
      let name = sessionStorage.getItem("user")
      //把name转成string类型

      //给全局变量name获取username
      this.name=JSON.parse(name)//转成字符串//转成字符串
      console.log(this.name+"test")

    }
  },
}

</script>

<style>
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}

.el-icon-arrow-down {
  font-size: 12px;
}
</style>